using GLib;

namespace Rob
{
	public class RobModules :GLib.Object
	{
		private GLib.KeyFile config;
		private string libfile;
		private string name;
		private string initfunc;
		private bool badd;
		private bool bremove;
		private string ruleconfig;
		private string actionconfig;
	
		
		construct
		{
			this.config = new GLib.KeyFile();
			bremove = false;
			badd = false;
			actionconfig = "/etc/rob/actions.conf";
			ruleconfig  = "/etc/rob/rules.conf";
		}
		private bool load_file(string file)
		{	
			try
			{
				this.config.load_from_file( file, GLib.KeyFileFlags.KEEP_COMMENTS|GLib.KeyFileFlags.KEEP_TRANSLATIONS );
			}
			catch(GLib.FileError e)
			{
				stdout.printf("Config file %s does not exit. Creating new\n", name);
			}
		}
		bool add( string name, string libfile , string init_func)
		{
				this.config.set_string(name, "libfile", libfile);
				this.config.set_string(name, "initfunc", init_func);
		}
		bool remove(string name)
		{
			try
			{
				config.remove_group( name );
			}
			catch ( GLib.KeyFileError e )
			{
				stderr.printf("%s does not exist", name);
				return false;
			}
		}

		static int main(string[] args)
		{
			int True = (int)true;
			int False = (int) false;
			OptionContext context = new GLib.OptionContext(args[0]);	
			OptionEntry[] entries =
			{
				{"--add", 'a', 0, GLib.INT, out badd, "Add a new modules to Rob", "Adds a new Module to Robs configuration\nNeeded options: name"},
				{"--remove", 'r', 0,GLib.OptionArg.INT, out bremove, "Remove a module from Rob", "Remove a Module from Robs Configuration. Needed Parameters: name, libfile, initfunction"},
				{ "--name", 'n', 0 , GLib.OptionsArg.String, out this.name, "The name of the module", "Basename of the Class to identify"},
				{ "--type", 't', 0 , GLib.OptionsArg.String, out this.type, "The Type of the module", "Type of the moduel. Either action or rule"},
		null
			};
		}
	}
}
